from socket import *
from time import ctime


HOST = ''
PORT = 33067
ADDR = (HOST, PORT)


tcp_server_sock = socket(AF_INET, SOCK_STREAM)  # 创建套接字
tcp_server_sock.bind(ADDR)  # 绑定ip。端口
tcp_server_sock.listen(5)   # 监听

while True:
    print('waiting for connection ...')
    tcp_cli_sock, addr = tcp_server_sock.accept()   # 接受请求，返回通信套接字和请求地址
    print(f'...connected from {addr}...')

    while True:
        data = tcp_cli_sock.recv(1024)  # 接受数据
        if not data:
            break
        tcp_cli_sock.send(f'[{bytes(ctime(), "utf-8")}] {data} '.encode('utf-8'))   # 发送数据

    tcp_cli_sock.close()

tcp_server_sock.close()